<?php
/**
 * 单页
 */
namespace App\Service;

use App\Models\EwMemberAuth;

class AgentService  extends BaseService
{

	public static function getList($params)
	{
		$where['limit'] = $params->page_num;
		$where['offset'] = ($params->p - 1)*$params->page_num;
		return EwMemberAuth::find($where);
	}

	public static function getInfo($id = 0)
	{
		return EwMemberAuth::findFirst($id);
	}

	public static function count()
	{
		return EwMemberAuth::count();
	}
	
	public static function save($data){
		$row = static::getInfo($data->member_id);
		if(!empty($row) && $row->state == 1){
			static::echoJson('Certification',402);
		}
		
		if(!empty($row) && $row->state == 2){
			static::echoJson('Certification through',402);
		}

		if(!empty($row) &&  $row->state == 3){
			return $row->save((array)$data);
		}			
		
		$model = new EwMemberAuth();
		$data->id = $data->member_id;
		$data->state = 1;
		return $model->save((array)$data);
	
	}
	
}